if !has('python3')
    echo "Error: Required vim compiled with +python"
    finish
endif

" Only do this when not done yet for this buffer
if exists("b:did_ftplugin_markdown_title_number")
    finish
endif

let b:did_ftplugin_markdown_title_number = 1

if !exists("g:auto_update_markdown_title_number_on_save")
    let g:auto_update_markdown_title_number_on_save = 0
endif

if !exists("g:toc_title_level")
    let g:toc_title_level = []
endif

"let s:pyfile = expand('<sfile>:p:h:h') . '/python/markdown.py'
"execute "py3file " . s:pyfile

let s:pydir = expand('<sfile>:p:h:h') . '/python'
execute 'py3 sys.path.insert(0, r"' . s:pydir . '")'
execute "py3 from edit_title_number import EditTitleNumber"
execute "py3 from edit_toc import EditToc"

command! -buffer MarkdownTitleNumberAdd :py3 EditTitleNumber().add_number(vim.current.buffer)
command! -buffer MarkdownTitleNumberRemove :py3 EditTitleNumber().remove_number(vim.current.buffer)
command! -buffer MarkdownTocAdd :py3 EditToc().insert_toc(vim.current.buffer, vim.current.window.cursor[0])
command! -buffer MarkdownTocUpdate :py3 EditToc().update_toc(vim.current.buffer)
